package Lesson;

import Homework.Commodity;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class SetTest {
    public static void main(String[] args) {
        Set<Commodity> set = new TreeSet<>(new Comparator<Commodity>() {
            @Override
            public int compare(Commodity o1, Commodity o2) {
                if (o2.getPrice() == o1.getPrice()){
                    return o2.getCode()-o1.getCode();
                }
                return Integer.parseInt(o2.getPrice())-Integer.parseInt(o1.getPrice());
            }
        });

        set.add(new Commodity(1,"香皂","10","香皂厂","2021-01-11"));
        set.add(new Commodity(2,"水","110","水厂","2021-02-11"));
        set.add(new Commodity(3,"鱼","50","鱼厂","2021-12-11"));

        Iterator<Commodity> it = set.iterator();
        while (it.hasNext()){
            Commodity a = it.next();
            System.out.println(a);
        }

        System.out.println("---------------");
        for (Commodity c:set){
            System.out.println(c);
        }



    }
}
